import { ref, computed, reactive } from 'vue'
import { defineStore } from 'pinia'
import { getApiList } from '../server'
import type { RootObject, Children, ChinaAdd, ChinaTotal, LocalCityNCOVDataList } from './type'

/* export const useStore = defineStore('counter', () => {
  const count = ref(0)
  const doubleCount = computed(() => count.value * 2)
  function increment() {
    count.value++
  }

  let list = ref<RootObject>()
  const getList = async () => {
    const result = await getApiList()
    list.value = result
    console.log(list)
  }




  return { count, doubleCount, increment, list, getList }


}) */

export const useStore = defineStore({
  id: 'store',
  state: () => ({
    list: <RootObject>{},
    item: <Children[]>[],
    chinaAdd: <ChinaAdd>{},
    chinaTotal: <ChinaTotal>{},
    cityDetail: <LocalCityNCOVDataList[]>[]
  }),
  actions: {
    async getList() {
      const result = await getApiList()
      this.list = result
      this.chinaAdd = this.list.diseaseh5Shelf.chinaAdd
      this.chinaTotal = this.list.diseaseh5Shelf.chinaTotal
      this.cityDetail = this.list.localCityNCOVDataList.slice(0, 10)
      // console.log(this.list)
    }
  }
})